/*
 *  ATrackEffect.cpp
 *  libavid
 *
 *  Created by Peter on 25.02.12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

#include "ATrackEffect.h"
#include "AStream.h"

A_IMPLEMENT_CLASS( 'TKFX', ATrackEffect, ATrackGroup );

void ATrackEffect::readFromStream( AStream& str, const AObjDoc& objd )
{
	ATrackGroup::readFromStream( str, objd );
	
	UInt8 tagMark, version;
	str.readPod( tagMark );
	str.readPod( version );
	TR_ASSERT( tagMark == 0x02 );
	TR_ASSERT( version == 0x06 );
	
	str.readPod( _leftLength );      
	str.readPod( _rightLength );     

	// GlobalInfo
	str.readPod( _globalInfoVersion );
	TR_CHECK( _globalInfoVersion == 0x02 );
	str.readPod( _kfCurrent );
	str.readPod( _kfSmooth ); 
	str.readPod( _colorItem );       
	str.readPod( _quality );
	str.readPod( _isReversed );
	_aspectOn = str.readBool();
	str.readPod( _keyFrameList ); // TODO: Resolve to a pointer via AObjDoc
	_forceSoftware = str.readBool();  
	_neverHardware = str.readBool();  
	
	// PClass Extension TrackMan
	str.readPod( tagMark );
	str.readPod( version );
	TR_ASSERT( tagMark == 0x01 );
	TR_ASSERT( version == 0x02 );
	str.readPod( tagMark );
	TR_ASSERT( tagMark == 72 );
	
	str.readPod( _trackMan ); // TODO: Resolve to pointer via AObjDoc

	// End TagMark
	// str.readPod( tagMark );
	//TR_ASSERT( tagMark == 0x03 );
	// FIXME: Derived classes of this come up, too, so we should really have the
	//        AObjDoc read the end tag mark instead of the individual classes.
	//        While at it, it could take care of all the version business, too if
	//        we put version info into the class registry like Avid does.
}

#define TRACE_FIELD( x ) "\t" #x ": " << x << std::endl
#define TRACE_CHAR_FIELD( x ) "\t" #x ": " << static_cast< int >( x ) << std::endl

void ATrackEffect::dump( std::ostream& str ) const
{
	str << "ATrackEffect {" << std::endl;
	
	str << "\t";
	ATrackGroup::dump( str );
	
	str << TRACE_FIELD( _leftLength );
	str << TRACE_FIELD( _rightLength );
	str << TRACE_FIELD( _globalInfoVersion );
	str << TRACE_FIELD( _kfCurrent );
	str << TRACE_FIELD( _kfSmooth );
	str << TRACE_FIELD( _colorItem );
	str << TRACE_FIELD( _quality );
	str << TRACE_CHAR_FIELD( _isReversed );
	str << TRACE_FIELD( _aspectOn );
	str << TRACE_FIELD( _keyFrameList );
	str << TRACE_FIELD( _forceSoftware );
	str << TRACE_FIELD( _neverHardware );
	str << TRACE_FIELD( _trackMan );
	
	str << "}" << std::endl;
}